package Group9.TodoManager.Actions;

import Group9.TodoManager.Data.Interface.ITableModel;
import Group9.TodoManager.DataStore.Repository;
import Group9.TodoManager.Settings;
import java.awt.event.ActionEvent;

/**
 * This action is responsible for opening window for updating a task.
 * @author volkan cambazoglu
 * @author Rupesh
 */
public class UpdateTaskAction<T> extends TodoManagerAction {

    private ITableModel<T> tableModel;
    private Repository<T> repository;
    
    /**
     * Constructor. Creates an instance of the UpdateTaskAction class.
     * @param table table model
     * @param repo repository
     */
    public UpdateTaskAction(ITableModel<T> table, Repository<T> repo) {
        tableModel = table;
        repository = repo;
    }

    /**
     * When this action is performed, it will show the create task UI
     * window
     * @param e event
     */
    @Override
    public void actionPerformed(ActionEvent e) {
        Settings.showDialog(Settings.getCreateTaskUI(null));
    }

    /**
     * When this action is executed, it will update the table model and
     * repository.
     * @param
     */
    @Override
    public void executeAction(Object param) {
        tableModel.setRowObject(tableModel.getSelectedRowIndex(),
        repository.updateItemProperty(tableModel.getRowObject(
                tableModel.getSelectedRowIndex()), "Priority",
                Integer.parseInt(param.toString())));

        repository.Commit();
    }
}
